package com.xbb.controller;


import com.xbb.entity.Autoconfig;
import com.xbb.entity.User;
import com.xbb.service.IAutoconfigService;
import com.xbb.util.Result;
import com.xbb.util.Result1;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 *  自动分配控制层
 * </p>
 *
 * @author Mr xie
 * @since 2020-06-03
 */
@RestController
@RequestMapping("/autoconfig")
public class AutoconfigController {

    @Autowired
    IAutoconfigService autoconfigService;

    /**
     * 获取自动分配列表
     * @return
     */
    @PostMapping("/getConfigAuto")
    public Object getConfigAuto(){
        Autoconfig autoconfig = autoconfigService.getById(1);
        return new Result1(0,"获取自动分配成功",autoconfig);
    }

    /**
     *设置分配开关打开
     * @return
     */
    @PostMapping("/setConfigAutoOn")
    public Object setConfigAutoOn(){
        Autoconfig autoconfig = new Autoconfig(1,1);
        boolean res = autoconfigService.updateById(autoconfig);
        if(res) {
            return new Result(0,"分配开关打开成功");
        }else {
            return new Result(1,"分配开关打开失败");
        }
    }

    /**
     *设置分配开关关闭
     * @return
     */
    @PostMapping("/setConfigAutoOff")
    public Object setConfigAutoOff(){
        Autoconfig autoconfig = new Autoconfig(1,0);
        boolean res = autoconfigService.updateById(autoconfig);
        if(res) {
            return new Result(0,"分配开关关闭成功");
        }else {
            return new Result(1,"分配开关关闭失败");
        }
    }
}
